package com.koala.upms.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.koala.common.core.utils.RT;
import com.koala.common.security.util.SecurityUtils;
import com.koala.upms.api.entity.SysUser;
import com.koala.upms.service.SysUserService;
import com.koala.upms.api.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author zhangchengji
 * @since 2019-05-11
 */
@RestController
@RequestMapping("/user" )
public class SysUserController   {
@Autowired
private SysUserService sysUserService;

@GetMapping("/findUserByUsername/{username}")
public RT findUserByUsername(@PathVariable String username){
    SysUser sysUser = sysUserService.getOne(Wrappers.<SysUser>query().lambda().eq(SysUser::getUsername, username));
    if (sysUser==null) {
        return new RT<> (Boolean.FALSE,"获取当前用户信息失败");
    }
    return new RT<>(sysUserService.getUserInfo(sysUser));
}
@GetMapping("/info")
public RT info(){
    String username = SecurityUtils.getUser().getUsername();
    SysUser sysUser = sysUserService.getOne(Wrappers.<SysUser>query().lambda().eq(SysUser::getUsername, username));
 return new RT<>(sysUserService.getUserInfo(sysUser));
}
@GetMapping("as/{a}")
public String as(@PathVariable String a){
    return "我是"+a;

}


///**
// * 通过ID查询
// *
// * @param id ID
// * @return SysUser
// */
//@GetMapping("/{id}" )
//public R<SysUser> get(@PathVariable Integer id){
//        return new R<>(sysUserService.selectById(id));
//        }
//
//
///**
//* 分页查询信息
//*
//* @param params 分页对象
//* @return 分页对象
//*/
//@RequestMapping("/page" )
//public Page page(@RequestParam Map<String, Object> params){
//        params.put(CommonConstant.DEL_FLAG,CommonConstant.STATUS_NORMAL);
//        return sysUserService.selectPage(new Query<>(params),new EntityWrapper<>());
//        }
//
///**
// * 添加
// * @param  sysUser 实体
// * @return success/false
// */
//@PostMapping
//public R<Boolean> add(@RequestBody SysUser sysUser){
//        return new R<>(sysUserService.insert(sysUser));
//        }
//
///**
// * 删除
// * @param id ID
// * @return success/false
// */
//@DeleteMapping("/{id}" )
//public R<Boolean> delete(@PathVariable Integer id){
//    SysUser sysUser =new SysUser();
//    sysUser.setId(id);
//    sysUser.setUpdateTime(new Date());
//    sysUser.setDelFlag(CommonConstant.STATUS_DEL);
//        return new R<>(sysUserService.updateById(sysUser));
//        }
//
///**
// * 编辑
// * @param  sysUser 实体
// * @return success/false
// */
//@PutMapping
//public R<Boolean> edit(@RequestBody SysUser sysUser){
//    sysUser.setUpdateTime(new Date());
//        return new R<>(sysUserService.updateById(sysUser));
//        }
        }
